package IC.Semantics.types;

import IC.AST.ICClass;

public class ClassType extends SemanticType
{
	private String superName;
	
	public ClassType(ICClass classNode) {
		super(classNode.getName());
		this.superName = classNode.getSuperClassName();
	}
	
	public ClassType(String name){
		super(name);
	}
	
	public String getSuperName(){
		return superName;
	}

	@Override
	public boolean subtypeOf(SemanticType t) 
	{
		// if the given type is not a class we return false
		if (!(t instanceof ClassType))
			return false;
		// if the given type is this class we return true because any class is a sub-type of itself
		if (t == this)
			return true;
		// if this class doesn't extends any class
		else if (this.superName == null) 
			return false;
		
		// if non of the above happened than we check if there exist some class upper in the inheritance tree that his type is t 
		return TypeTable.getClassType(superName).subtypeOf(t); 
	}
	
	
	public String toString()
	{
		String dump = null;
		dump = superName == null ? name : name + ", Superclass ID: " + TypeTable.getClassType(superName).id;
		
		return dump;
	}

	
}
